﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Dala.Utilities;
using System.IO;

namespace Dala.Samples.DataAccessLayer
{
    public partial class DalaDataSource
    {
        private static DataSet _dataSet;
        private static DataSet DataSet
        {
            get
            {
                if (System.Web.HttpContext.Current.Session != null && System.Web.HttpContext.Current.Session["DataSet"] != null)
                {
                    _dataSet = System.Web.HttpContext.Current.Session["DataSet"] as DataSet;
                }

                if (_dataSet == null)
                {
                    _dataSet = new DataSet();
                    _dataSet.ReadXmlSchema(HttpContext.Current.Server.MapPath(@"~/App_Logic/XML-XSD/data.xsd"));

                    DirectoryInfo dInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath(SiteSettings._SAMPLE_XML_LOCATION));
                    FileInfo[] samleDataFiles = dInfo.GetFiles();
                    foreach (FileInfo samleDataFile in samleDataFiles)
                    {
                        _dataSet.ReadXml(samleDataFile.FullName);
                    }
                    if (System.Web.HttpContext.Current.Session != null)
                    {
                        System.Web.HttpContext.Current.Session["DataSet"] = _dataSet;
                    }
                }
                return _dataSet;
            }
        }
    }
}